package com.minyifang.wcspf.work.ui.user.activities;

import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.minyifang.wcspf.R;
import com.minyifang.wcspf.common.base.BaseMvpActivity;
import com.minyifang.wcspf.common.utils.ToastHelper;
import com.minyifang.wcspf.common.utils.ToastUtils;
import com.minyifang.wcspf.work.model.HttpRespond;
import com.minyifang.wcspf.work.ui.user.presenter.ComplainPresenter;
import com.minyifang.wcspf.work.ui.user.view.ComplainView;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 我要投诉
 */
public class ComplainActivity extends BaseMvpActivity<ComplainView, ComplainPresenter> implements ComplainView {

    @BindView(R.id.tv1)
    TextView mTv1;
    @BindView(R.id.tv2)
    TextView mTv2;
    @BindView(R.id.tv3)
    TextView mTv3;
    @BindView(R.id.edt_content)
    EditText mEdtContent;
    @BindView(R.id.btn_commit)
    Button mBtnCommit;

    private int type = 2; //1提交意见 2反馈错误 3发起投诉

    @Override
    protected int setContentLayoutRes() {
        return R.layout.activity_complain;
    }

    @Override
    protected void initView() {
        setSelect(mTv2, mTv1, mTv3);
        mEdtContent.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String str = s.toString();
                if (!TextUtils.isEmpty(str)) {
                    mBtnCommit.setEnabled(true);
                } else
                    mBtnCommit.setEnabled(false);
            }
        });
    }

    @Override
    protected void initData() {

    }

    @OnClick({R.id.tv1, R.id.tv2, R.id.tv3, R.id.btn_commit})
    void clickAction(View view) {
        switch (view.getId()) {
            case R.id.tv1:
                type = 1;
                setSelect(mTv1, mTv2, mTv3);
                break;
            case R.id.tv2:
                type = 2;
                setSelect(mTv2, mTv1, mTv3);
                break;
            case R.id.tv3:
                type = 3;
                setSelect(mTv3, mTv1, mTv2);
                break;
            case R.id.btn_commit:
                commit();
                break;
        }
    }

    private void commit() {
        mPresenter.commitComplain(mEdtContent.getText().toString(), type);
    }

    private void setSelect(TextView... view) {
        view[0].setSelected(true);
        view[1].setSelected(false);
        view[2].setSelected(false);
    }

    @Override
    protected ComplainPresenter createPresenter() {
        return new ComplainPresenter();
    }

    @Override
    public void showLoadingView() {
        showLoadingDialog();
    }

    @Override
    public void hideLoadingView() {
        hideLoadingDialog();
    }

    @Override
    public void onNetworkError() {
        hideLoadingDialog();
    }

    @Override
    public void showComplainRes(HttpRespond<String> respond) {
        ToastHelper.getInstance(this).showSucceed(respond.message);
        finish();
    }

    @Override
    public void showRequestFailed(String message) {
        ToastHelper.getInstance(this).showWarn(message);
    }
}
